package entity_model.json.deserializers;

import com.google.gson.*;
import entity_model.Entity;
import entity_model.Relationship;
import utils.titles.Title;

import java.lang.reflect.Type;

/**
* Created by nuno-rafael-figueiredo on 13-05-2014.
*/
public class RoleDeserializer implements JsonDeserializer<Relationship.Role> {
    @Override
    public Relationship.Role deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        final JsonObject jsonObject = json.getAsJsonObject();

        return new Relationship.Role(
                Relationship.Role.Cardinality.valueOf(jsonObject.get("cardinality").getAsString()),
                context.deserialize(jsonObject.get("entity"), Entity.class),
                Title.fromLowered(jsonObject.get("name").getAsString())
        );
    }
}
